package advance.juc;

import java.util.concurrent.*;

public class ThreadExecutorButilBuilder {

    private static int defaultCorePoolSize = 200;

    private static int defaultMaximumPoolSize = 1024;

    private static long defaultKeepAliveTime = 0L;

    private static TimeUnit defaulUnit = TimeUnit.MILLISECONDS;

    private static BlockingQueue<Runnable> defaultWorkQueue = new LinkedBlockingQueue(2000);

    private static ThreadPoolExecutor es = null;


    static {
        System.out.println("static");
        es = new ThreadPoolExecutor(200,
                1024,
                0L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(20000));
    }

    public static ThreadExecutorButilBuilder buildThreadExecutorUtilBuilder(int corePoolSize,
                                                                            int maximumPoolSize,
                                                                            long keepAliveTime,
                                                                            TimeUnit unit,
                                                                            int blockQueueSize) {
        es = new ThreadPoolExecutor(corePoolSize,
                maximumPoolSize,
                keepAliveTime,
                unit,
                new LinkedBlockingQueue<Runnable>(blockQueueSize));
        return new ThreadExecutorButilBuilder();
    }

    private ThreadExecutorButilBuilder() {

    }

    public static void runTask(Runnable runnable) {
        long t = System.currentTimeMillis();
        es.execute(runnable);
        int count = 0;

        try {
            count = ((ThreadPoolExecutor) es).getActiveCount();
        } catch (Exception var5) {
        }

        if (count > 10) {
        }

    }

    public static void stopTask() {
        es.shutdown();
    }

    public static void test() {
        System.out.println("hello");
    }

    public static void main(String[] args) {
        ThreadExecutorButilBuilder.buildThreadExecutorUtilBuilder(100, 1024, 0, TimeUnit.SECONDS, 1000).runTask(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello");
            }
        });

    }

}
